﻿using System;
using System.Collections.Generic;

namespace TempEmployees.BLL.UserAccess.ActiveDirectory
{
    public class ActiveDirectoryResultsParser
    {
        private Dictionary<string, List<string>> m_result;

        public ActiveDirectoryResultsParser(Dictionary<string, List<string>> result)
        {
            m_result = result;
        }

        public int ParseRoles(ref int departmentId)
        {
            List<string> memberOf = m_result["memberof"];
            int roles = 0;
            foreach (string content in memberOf)
            {
                int role = ActiveDirectoryValueConversions.ToRoleID(content, ref departmentId);
                roles |= role;
            }
            return roles;
        }

        public string ParseID()
        {
            return (m_result.ContainsKey("employeeid")) ? m_result["employeeid"][0] : string.Empty;
        }

        public void ParseName(out string first, out string last)
        {
            first = (m_result.ContainsKey("givenname")) ? m_result["givenname"][0] : string.Empty;
            last = (m_result.ContainsKey("sn")) ? m_result["sn"][0] : string.Empty;
        }
    }
}